﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Apprenda.SaaSGrid;

namespace root.Controllers
{
    public class CommonController : Controller
    {

        public JsonResult SearchUsers(string searchTerm)
        {
            var term = searchTerm.Trim().ToLowerInvariant();
            var allUsers = TenantContext.Current.GetUsers();
            var matchingUsers = allUsers.Where(potentialUser => 
                                               potentialUser.FirstName.ToLowerInvariant().StartsWith(term) ||
                                               potentialUser.LastName.ToLowerInvariant().StartsWith(term)
                                              );            
            return Json(matchingUsers, JsonRequestBehavior.AllowGet);
        }

    }
}
